package cn.wfu.rlrjds.web.admin.service.ipml;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wfu.rlrjds.web.admin.dao.IAdminDao;
import cn.wfu.rlrjds.web.admin.domain.Admin;
import cn.wfu.rlrjds.web.admin.service.IAdminService;

@Service
@Transactional(readOnly = true)
public class AdminServiceIpml implements IAdminService {

	@Autowired
	private IAdminDao adminDao;

	@Override
	public Admin login(Admin form) throws AdminException {
		// TODO Auto-generated method stub
		if (form == null) {
			throw new RuntimeException("管理员控制层传入的参数为空");
		}
		Admin admin = this.adminDao
				.findBy("findByUsername", form.getUsername());
		if (admin == null) {
			throw new AdminException("管理员账号不存在");
		} else if (!form.getPassword().equals(admin.getPassword())) {
			throw new AdminException("密码不正确");

		}
		return admin;

	}
}
